package com.longxi.tianjintianbao.ui.fragment.mian;

import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.activity.main.MainActivity;
import com.longxi.tianjintianbao.ui.base.LazyFragment;
import com.longxi.tianjintianbao.ui.presenter.main.MessageFgPresenter;
import com.longxi.tianjintianbao.ui.view.main.IMessageFgView;

/**
 * @创建者 Kuma
 * @描述 消息
 */
public class MessageFragment extends LazyFragment<IMessageFgView, MessageFgPresenter> implements IMessageFgView {

    private final String TAG = "MessageFragment";

    @Override
    protected void init(View view) {
        mPresenter.setBar();
        mPresenter.initAdapter();
        mPresenter.setData();
    }

    @Override
    public void initListener() {
        super.initListener();
    }

    @Override
    protected MessageFgPresenter createPresenter() {
        return new MessageFgPresenter((MainActivity)getActivity(), this);
    }

    @Override
    public void onDestroy() {
        mPresenter.onDestroy();
        super.onDestroy();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.fragment_message;
    }

    @Override
    public RecyclerView getRvContent() {
        return mRvContent;
    }

    public void refreshMessage(boolean nowRefresh){
        if(mPresenter == null){
            return;
        }
        if(nowRefresh){
            mPresenter.onResume();
        }else{
            mPresenter.setRefresh(true);
        }
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            if(mPresenter != null){
                mPresenter.onResume();
            }
        } else {
//            if(mPresenter != null){
//                mPresenter.onPause();
//            }
        }
    }
}

